/*
 * Part of the ACID Project
 * Developed in 2011 by Morgan Taschuk
 */
package acid.parse;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author morgan
 */
public class ParseTopTableResults
{

    private ParseTopTableResults()
    {
    }

    public static List<GANRow> parse(String filename) throws IOException
    {
        List<GANRow> rows = new ArrayList<GANRow>();

        BufferedReader reader = new BufferedReader(new FileReader(filename));

        String line = reader.readLine();
        if (!line.contains("\"P.Value\""))
        {
            throw new IOException("Incorrect file format");
        }
        line = reader.readLine();
        while (line != null)
        {
            if (!line.trim().equals(""))
            {
                String[] splitLine = line.split("\\t");
                int id = new Integer(splitLine[0].replace("\"", ""));
                String geneName = splitLine[1].replace("\"", "");
                Double foldChange = new Double(splitLine[2].replace("\"", ""));
                Double pVal = new Double(splitLine[6].replace("\"", ""));
                rows.add(new GANRow(id, geneName, pVal, foldChange));
                line = reader.readLine();
            }
        }

        return rows;
    }
}
